import request from '@/utils/request.js';

/**
 * 职位相关API接口
 */

// 获取HR发布的职位列表
export function getHrJobListApi(data) {
  return request({
    url: '/portal/job/get_hr_job_list',
    method: 'post',
    data
  });
}

// 搜索职位列表（求职者端）
export function searchJobsApi(data) {
  return request({
    url: '/portal/job/search/jobs',
    method: 'post',
    data
  });
}

// 获取职位详情
export function getJobDetailApi(jobId) {
  return request({
    url: `/portal/job/detail/${jobId}`,
    method: 'get'
  });
}

// 获取职位搜索详情（求职者端）
export function getJobSearchDetailApi(jobId) {
  return request({
    url: '/portal/job/search/detail',
    method: 'get',
    data: { jobId }
  });
}

// 关闭职位
export function closeJobApi(jobId) {
  return request({
    url: '/portal/job/close',
    method: 'get',
    data: { jobId }
  });
}

// 开启职位
export function openJobApi(jobId) {
  return request({
    url: '/portal/job/open',
    method: 'post',
    data: { jobId }
  });
}

// 获取用户求职期望
export function getMyWorkExpectApi() {
  return request({
    url: '/portal/resume/my_work_expect',
    method: 'get'
  });
}

export function submitPositionApi(data) {
  return request({
    url: '/portal/job/submit',
    method: 'post',
    data
  });
}

// 获取举报上传签名
export function getReportUploadSignsApi(count) {
  return request({
    url: '/portal/job/report/get_signs',
    method: 'get',
    data: { count }
  });
}

// 提交举报
export function submitReportApi(data) {
  return request({
    url: '/portal/job/report/submit',
    method: 'post',
    data
  });
}

// 获取所有职位数量
export function getAllJobCountApi() {
  return request({
    url: '/portal/job/get_all_job_count',
    method: 'get',
    showLoading: false // 不显示加载动画
  });
}

// 获取公司公开职位列表
export function getCompanyOpenJobListApi(params) {
  return request({
    url: '/portal/job/get_company_open_job_list',
    method: 'get',
    data: params,
    showLoading: false // 不显示加载动画
  });
}

/**
 * 收藏职位
 * @param {string} jobId - 职位ID
 * @returns {Promise}
 */
export function collectJobApi(jobId) {
  return request({
    url: `/portal/job/collect?jobId=${jobId}`,
    method: "POST",
  });
}

/**
 * 取消收藏职位
 * @param {string} jobId - 职位ID
 * @returns {Promise}
 */
export function uncollectJobApi(jobId) {
  return request({
    url: `/portal/job/uncollect?jobId=${jobId}`,
    method: "POST",
  });
}

/**
 * 查询职位收藏状态
 * @param {string} jobId - 职位ID
 * @returns {Promise<boolean>}
 */
export function isJobCollectedApi(jobId) {
  return request({
    url: "/portal/job/is_collected?jobId=" + jobId,
    method: "GET",
  });
}

/**
 * 获取收藏职位总数
 * @returns {Promise<number>}
 */
export function getCollectedJobCountApi() {
  return request({
    url: "/portal/job/collected/count",
    method: "GET"
  });
}

/**
 * 获取收藏职位列表
 * @param {Object} params - 分页参数
 * @param {number} params.pageNo - 页码
 * @param {number} params.pageSize - 每页数量
 * @returns {Promise}
 */
export function getCollectedJobListApi(params) {
  console.log(params);
  
  return request({
    url: "/portal/job/collected/list",
    method: "GET",
    data: params
  });
}